package com.xing.service.impl;

import com.xing.dao.RoleFunctionMapper;
import com.xing.entity.pojo.RoleFunctionKey;
import com.xing.service.RoleFunctionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class RoleFunctionServiceImpl implements RoleFunctionService {
    @Autowired
    private RoleFunctionMapper roleFunctionMapper;
    @Override
    public void insertSelective(String[] functionId,String roleId) {
        List<RoleFunctionKey> list=new ArrayList<>();

        for (String s : functionId) {
            RoleFunctionKey roleFunctionKey = new RoleFunctionKey();
            roleFunctionKey.setFunctionId(s);
            roleFunctionKey.setRoleId(roleId);
            list.add(roleFunctionKey);
        }

        for (RoleFunctionKey functionKey : list) {
            roleFunctionMapper.insertSelective(functionKey);
        }
    }

    @Override
    public List<RoleFunctionKey> findByUId(String roleId) {
        return roleFunctionMapper.findByUId(roleId);
    }

    @Override
    public int deleteByRoleId(String roleId) {
        return roleFunctionMapper.deleteByRoleId(roleId);
    }

    @Override
    public List<RoleFunctionKey> findByFunId(String funId) {
        return roleFunctionMapper.findByFunId(funId);
    }
}
